package com.telit.firecommand.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.telit.common.exception.ForestBaseException;
import com.telit.firecommand.dao.CommHistoryFireDao;
import com.telit.firecommand.dao.ForestLandInformationDao;
import com.telit.firecommand.entity.CommHistoryFire;
import com.telit.firecommand.entity.ForestLandInformation;
import com.telit.firecommand.service.ForestLandInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * @Author:zhangwei
 * @Description:
 * @Time:Created on 2022/9/27 9:08
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ForestLandInformationServiceImpl extends ServiceImpl<ForestLandInformationDao, ForestLandInformation> implements ForestLandInformationService {

    @Autowired
    private CommHistoryFireDao commHistoryFireDao;

    @Override
    @Transactional
    public void add(ForestLandInformation forestLandInformation) {
//        ForestLandInformation entity = getForestLandInformation(forestLandInformation);
//        if(baseMapper.insert(entity)<=0){
//            throw new ForestBaseException("新增林班信息失败");
////        }
//        CommHistoryFire commHistoryFire = new CommHistoryFire();
//        commHistoryFire.setSlope(forestLandInformation.getFireSlope());
//        commHistoryFire.setAltitude(forestLandInformation.getFireAltitude());
//        commHistoryFire.setSlopeAspect(forestLandInformation.getFireSlopeAspect());
//        commHistoryFire.setSlopePosition(forestLandInformation.getFireSlopePosition());
//        //这里拿到火电对应林地的坡度坡向 填充火电对应的坡度坡向， 没有让前端再次传火电的坡度坡向
//        //判断是否已经存在了历史火情
//        Long id = commHistoryFireDao.selecthFire(forestLandInformation.getFireId());
//        if (id!=null){
//            //修改数据
//           commHistoryFire.setId(id);
//            commHistoryFireDao.updateByPrimaryKeySelective(commHistoryFire);
//        }else {
//            //新增
//            commHistoryFire.setFireId(forestLandInformation.getFireId());
//            commHistoryFireDao.insertSelective(commHistoryFire);
//        }
    }



    @Override
    public ForestLandInformation forestLandInformation(String fireId) {
        ForestLandInformation forestLandInformation=  baseMapper.forestLandInformation(fireId);
        return forestLandInformation;
    }



    private ForestLandInformation getForestLandInformation(ForestLandInformation forestLandInformation) {
        ForestLandInformation entity = new ForestLandInformation();
        entity.setForestCompartments(forestLandInformation.getForestCompartments());
        entity.setLandType(forestLandInformation.getLandType());
        entity.setSlope(forestLandInformation.getSlope());
        entity.setSlopeAspect(forestLandInformation.getSlopeAspect());
        entity.setSlopePosition(forestLandInformation.getSlopePosition());
        entity.setAltitude(forestLandInformation.getAltitude());
        entity.setForestType(forestLandInformation.getForestType());
        entity.setAgeGroup(forestLandInformation.getAgeGroup());
        entity.setDominantTreeSpecies(forestLandInformation.getDominantTreeSpecies());
        entity.setTreeSpeciesComposition(forestLandInformation.getTreeSpeciesComposition());
        entity.setFireId(forestLandInformation.getFireId());
        return entity;
    }
}
